<?php
if(!isset($_SERVER['PHP_AUTH_USER'])){
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: Basic realm="Top Secret"');
    exit;
} else {
    $link = mysql_connect('localhost', 'dinah', 'dinah')
            or die('Could not connect: ' . mysql_error());
    mysql_select_db('dinah_users') or die('Could not select database');
    $query = "SELECT * FROM users where login='{$_SERVER['PHP_AUTH_USER']}' AND password=MD5('{$_SERVER['PHP_AUTH_PW']}');";
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    if(count(mysql_fetch_array($result)) <= 1) {
        header('HTTP/1.1 401 Unauthorized');
        header('WWW-Authenticate: Basic realm="Top Secret"');
        exit;
    }
    mysql_free_result($result);
    mysql_close($link);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8;charset=utf-8"/>
  <title>Down the Rabbit Hole ...</title>

  <script src="js/jquery-1.4.2.min.js"></script>
  <script src="js/jquery-ui-1.8rc3.custom.min.js"></script>
  <script src="js/json2.js"></script>

  <script src="js/order/init.js"></script>
  <script src="js/order/prototypes.js"></script>
  <script src="js/order/utilities.js"></script>
  <script src="js/order/initRelations.js"></script>
  <script src="js/order/initCollections.js"></script>
  <script src="js/order/newLine.js"></script>
  <script src="js/order/updateImages.js"></script>
  <script src="js/order/autocomplete.js"></script>
  <script src="js/order/request.js"></script>
  <script src="js/order/makeHideable.js"></script>
  <script src="js/order/openPage.js"></script>
  <script src="js/order/initFiles.js"></script>

  <link type="text/css" href="css/order.css" rel="stylesheet" />
  <link type="text/css" href="css/jquery-ui-1.8rc3.custom.css" rel="stylesheet" />
</head>

<body>
  <div id="menu">

    <div id="userName"><?php echo($_SERVER['PHP_AUTH_USER']) ?></div>

    <input type="text" id="openCollection" autocomplete="off"/>
    <button id="search">Nav</button>
    <button id="couvertures">Couv</button>

    <span id="selectOperation" title="choisir une opération">...</span>
    <select id="pagesOperations">
        <option value="CopyAfter">Copier après</option>
        <option value="CopyBefore">Copier avant</option>
    </select>
    
    <span id="trace" title="accéder à la trace">?</span>
    <button id="traceBtn">trace</button>

	<span id="subjectLabel" href="">Sujet</span>
	<form id="postRelations" method="post" action="makeRelations.php" target="_blank">
		<input type="text" name="relationLabel" id="relationLabel" autocomplete="off"/>
		<input type="hidden" name="subject" id="subject"/>
		<input type="hidden" name="relationId" id="relationId"/>
		<input type="hidden" name="object" id="object"/>
		<input type="hidden" name="user" id="user"/>
		<input type="submit" value="Lier"/>
	</form>
	<span id="objectLabel" href="">Objet</span>
	<input type="text" id="termLabel" autocomplete="off"/>
	<button id="clearBtn">RAZ</button>
  </div>
  <div id="files">
	<div>
  		<input type="text" id="newFileName"/>
		<button id="newFileBtn">créer</button>
	</div>
	<div id="filesLabels">
		<span class="fileLabel">divers</span>
	</div>
  </div>
  <div id="lines"></div>
</body>
</html>
<?php
}
?>
